/*
 * @ProjectName: 编程学习
 * @Copyright:   2019 HangZhou Yi Dev, Ltd. All Right Reserved.
 * @address:     https://yiyuery.github.io/
 * @date:        2019/5/20 20:57
 * @email:       xiazhaoyang@live.com
 * @description: 本内容仅限于编程技术学习使用，转发请注明出处.
 */
package com.yi.yier.boot.autoconfigure.codegenerator.api.service.mybatis;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author Yi
 * @version v1.0.0
 * @date 2019-06-29 21:25
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify By: {修改人} 2019-06-29
 * @modify reason: {方法名}:{原因}
 * ...
 */
public abstract class BaseMybatisServiceImpl<Record, Example> implements BaseMybatisService<Record, Example> {

    public abstract BaseMybatisMapper<Record, Example> getMapper();

    @Override
    public long countByExample(Example example) {
        return getMapper().countByExample(example);
    }

    @Override
    public int deleteByExample(Example example) {
        return getMapper().deleteByExample(example);
    }

    @Override
    public <ID> int deleteByPrimaryKey(ID recordId) {
        return getMapper().deleteById(recordId);
    }

    @Override
    public int insert(Record record) {
        return getMapper().insert(record);
    }

    @Override
    public int insertSelective(Record record) {
        return getMapper().insertSelective(record);
    }

    @Override
    public int insertList(List<Record> records) {
        return getMapper().insertList(records);
    }

    @Override
    public int insertListSelective(List<Record> records) {
        return getMapper().insertListSelective(records);
    }

    @Override
    public int updateListByPrimaryKey(List<Record> records) {
        return getMapper().updateListByPrimaryKey(records);
    }

    @Override
    public List<Record> selectByExample(Example example) {
        return getMapper().selectByExample(example);
    }

    @Override
    public <ID> Record selectByPrimaryKey(ID recordId) {
        return getMapper().selectByPrimaryKey(recordId);
    }

    @Override
    public int updateByExampleSelective(Record record, Example example) {
        return getMapper().updateByExampleSelective(record, example);
    }

    @Override
    public int updateByExample(Record record, Example example) {
        return getMapper().updateByExample(record, example);
    }

    @Override
    public int updateByPrimaryKeySelective(Record record) {
        return getMapper().updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Record record) {
        return getMapper().updateByPrimaryKey(record);
    }

    /**
     * 根据条件查询记录并按页码分页,不查询总数
     *
     * @param example  条件
     * @param pageNo   页数
     * @param pageSize 每页记录数
     * @return
     */
    @Override
    public List<Record> selectByExampleForPage(Example example, Integer pageNo, Integer pageSize) {
        return PageHelper.startPage(pageNo, pageSize, false).doSelectPage(() -> getMapper().selectByExample(example));
    }

    /**
     * 根据条件查询记录并按页码分页
     *
     * @param example  条件
     * @param pageNo   页数
     * @param pageSize 每页记录数
     * @return
     */
    @Override
    public PageInfo<Record> selectByExampleForPageInfo(Example example, Integer pageNo, Integer pageSize) {
        return PageHelper.startPage(pageNo, pageSize).doSelectPageInfo(() -> getMapper().selectByExample(example));
    }

    /**
     * 根据条件查询记录并按偏移量分页,不查询总数
     *
     * @param example
     * @param limit
     * @param offset
     * @return
     */
    @Override
    public List<Record> selectByExampleForLimit(Example example, Integer limit, Integer offset) {
        return PageHelper.offsetPage(offset, limit, false).doSelectPage(() -> getMapper().selectByExample(example));
    }
}
